package DataCollect;

import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.interceptor.Interceptor;

import java.util.ArrayList;
import java.util.List;

public class MyInterceptor implements Interceptor {
    //初始化
    @Override
    public void initialize() {

    }
    //处理单个Event
    @Override
    public Event intercept(Event event) {
        byte[] body = event.getBody();
        String line = new String(body);
        String[] infos = line.split("\\|");
        if (infos.length>=4){
            return event;
        }
        return null;
    }
    //处理多条event
    @Override
    public List<Event> intercept(List<Event> events) {
        ArrayList<Event> eventList = new ArrayList<>();
        for (Event event : events) {
            Event interceptEvent = intercept(event);
            if (interceptEvent!= null){
                eventList.add(event);
            }
        }
        return eventList;
    }

    @Override
    public void close() {

    }

    public static class builder implements Interceptor.Builder{

        @Override
        public Interceptor build() {

            return new MyInterceptor();
        }

        @Override
        public void configure(Context context) {

        }
    }
}
